<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Model\User as UserModel;
use App\Controller\BaseController;

#[AutoController]
class FriendController extends BaseController
{
    private $request;

    /**
     * 获取好友列表
     */
    public function friendlist(RequestInterface $request)
    {
        $isAuth = $this->Auth($request, 1);
        $AuthInfo = json_decode($isAuth, true);
        if ($AuthInfo['err'] === 0) {
            $friendList = json_encode(UserModel::getFriendList($AuthInfo['token']));
            $res['err'] = 0;
            $res['msg'] = 'toekn认证成功';
            $res['friendList'] = $friendList;
        } else {
            $res['err'] = 1;
            $res['msg'] = '登录失效，正在跳转...';
            $res['friendList'] = '';
        }
        return json_encode($res);
    }
}
